package com.lanou.dllo.baisibudejie.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lanou.dllo.baisibudejie.R;
import com.lanou.dllo.baisibudejie.application.BaseApplication;

/**
 * Created by dllo on 15/10/27.
 */
public class InstalledActivity extends Activity implements View.OnClickListener {

    private TextView installed_backTv, clearCacheTv, shareTv;
    private Button installed_exitBtn;
    private boolean isLogin;
    private boolean qqLogin, isExit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_installed);
        initView();

    }

    private void initView() {
        Intent intent = getIntent();
        isLogin = intent.getBooleanExtra("isLogin", false);//true
        qqLogin = intent.getBooleanExtra("qqLogin", false);//false
        isExit = intent.getBooleanExtra("isExit", true);//false
        installed_backTv = (TextView) findViewById(R.id.installed_backTv);//返回
        installed_backTv.setOnClickListener(this);
        installed_exitBtn = (Button) findViewById(R.id.installed_exitBtn);//退出登录
        //判断是否登录设置退出按钮能不能点击
        if (!qqLogin && !isLogin && isExit) {
            installed_exitBtn.setEnabled(false);
        } else if (isLogin || qqLogin || !isExit) {
            installed_exitBtn.setEnabled(true);
        }
        installed_exitBtn.setOnClickListener(this);
        clearCacheTv = (TextView) findViewById(R.id.clearCacheTv);//清除缓存
        clearCacheTv.setOnClickListener(this);
        shareTv = (TextView) findViewById(R.id.shareTv);//推荐给朋友
        shareTv.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.installed_backTv://点击返回
                finish();
                break;
            case R.id.installed_exitBtn://退出登录
                BaseApplication.setIsLogin(false);
                Intent intent_exit = new Intent();
                intent_exit.putExtra("isLogin", false);
                intent_exit.putExtra("isExit", true);
                if (qqLogin) {
                    intent_exit.putExtra("qqLogin", true);
                } else {
                    intent_exit.putExtra("qqLogin", false);
                }

                setResult(500, intent_exit);
                finish();
                break;
            case R.id.clearCacheTv://清除缓存

                break;
            case R.id.shareTv://推荐给朋友

                break;
        }
    }

}
